<?php

class Users extends CActiveRecord
{	
	/**
	 * Returns the static model of the specified AR class.
	 * @return CActiveRecord the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{users}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array();
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'feeds' => array(self::HAS_MANY, 'FeedList', 'user_id'),
			'friendship' => array(self::HAS_MANY, 'FriendShip', 'user_id'),
			'userprofile' => array(self::BELONGS_TO, 'Profile', 'id'),
		);
	}

	/**
	 * @验证密码
	 */
	public function validatePassword($password)
	{
		return $this->hashPassword($password)===$this->password;
	}

	/**
	 * @生成密码
	 */
	public function hashPassword($password)
	{
		return md5($password);
	}
}